<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//购物车控制器
class ShopcarController extends Controller{
	
	
    // 购物车首页
    public function index(){
     
      $goodData = Cart::getAllData();
      // p($goodData);die;

      View::with('goodData',$goodData);

      View::make();
    }


    public function add(){
     


            $id = Q('get.gid',0,'intval');
            $goodModel = new \Common\Model\Good;
            $name = $goodModel->where("gid={$id}")->pluck('gname');
           
            $v=explode(',',Q('get.value'));
            // p($v);die;
            $data=array(
                  'id'=>$id,
                  'name'=>$name,
                  'num'=>$v[4],
                  'price' =>$v[2],
                  'options'=>array(
                          'color'=> $v[0], 
                          'size'=> $v[1],
                          'pic'=>$v[3]
                    ),
              );
             // p($data);
            Cart::add($data);
            // View::success('添加成功',U('index'));
            go(U('index'));
   
   } 
    public function del(){
      $id = Q('get.gid');
      unset($_SESSION['cart']['goods'][$id]);
      go(U('Shopcar/index'));

    }




}
?>